package com.bravo.qa.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.bravo.qa.entity.Problem;
import org.springframework.data.jpa.repository.Query;

/**
 * problem数据访问接口
 * @author Yuyong
 *
 */
public interface ProblemRepository extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

    /**
     * 根据标签ID查询最新问题列表
     * @param labelId
     * @param pageable
     * @return
     */
    @Query(value = "select * from tb_problem p where id in (select problem_id from tb_pl where label_id = ?1) order by reply_time desc",nativeQuery = true)
    Page<Problem> findNewListByLabelId(String labelId, Pageable pageable);

    /**
     * 根据标签ID查询热门问题列表
     * @param labelId
     * @param pageable
     * @return
     */
    @Query(value = "select * from tb_prolbem p where id in (select proboem_id from tb_pl where label_id = ?1) order by reply desc",nativeQuery = true)
    Page<Problem> findHotListByLabelId(String labelId,Pageable pageable);

    /**
     * 根据标签ID查询等待回答列表
     * @param labelId
     * @param pageable
     * @return
     */
    @Query(value = "select * from tb_prolbem p where id in (select proboem_id from tb_pl where label_id = ?1)and reply = 0 order by create_time desc",nativeQuery = true)
    Page<Problem> findWaitListByLabelId(String labelId,Pageable pageable);
}
